package com.swt.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.swt.domain.TbUserAddr;
import com.swt.service.TbUserService;
import com.swt.domain.TbUser;
import com.swt.mapper.TbUserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
* @author 苏
* @description 针对表【yesapi_xbinstore_tb_user(B2C商城-用户表)】的数据库操作Service实现
* @createDate 2022-05-16 09:40:37
*/
@Service
public class TbUserServiceImpl implements TbUserService {

    @Autowired
    private TbUserMapper tbUserMapper;
    @Override

    public List<TbUser> selectAllTbUser() {
        return tbUserMapper.selectList(null);
    }

    @Override
    public int delectTbUser(String id) {
        return tbUserMapper.deleteById(id);
    }

    @Override
    public int updateTbUser(TbUser TbUser) {
        return tbUserMapper.updateById(TbUser);
    }

    @Override
    public int inserTbUser(TbUser TbUser) {
        return tbUserMapper.insert(TbUser);
    }

    @Override
    public TbUser selectbyTbUser(String id) {
        return tbUserMapper.selectById(id);
    }

    @Override
    public Page<TbUser> pageTbUser(Integer page, Integer start,TbUser tbUser) {
        Page<TbUser> userPge = new Page<>(page,start);
        LambdaQueryWrapper<TbUser> use = new LambdaQueryWrapper<>();
        use.orderByDesc(TbUser::getCreateTime);
        use.like(StringUtils.isNotEmpty(tbUser.getName()), TbUser::getName, tbUser.getName());
        use.like(StringUtils.isNotEmpty(tbUser.getGender()), TbUser::getGender, tbUser.getGender());
        use.like(StringUtils.isNotEmpty(tbUser.getPhone()), TbUser::getPhone, tbUser.getPhone());
        use.like(StringUtils.isNotEmpty(tbUser.getEmail()), TbUser::getEmail, tbUser.getEmail());
        return tbUserMapper.selectPage(userPge,use);
    }


}




